package com.example.compreshensiveshop.controller;

import com.example.compreshensiveshop.dto.CustomerUpdateDTO;
import com.example.compreshensiveshop.service.CustomerService;
import com.example.compreshensiveshop.utils.QiniuKodoUtil;
import com.example.compreshensiveshop.vo.CustomerMessageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private QiniuKodoUtil qiniuKodoUtil;
    /**
     * 查询用户信息
     * @param customerId
     * @return
     */
    @GetMapping("queryMessage")
    public CustomerMessageVO queryMessage(@RequestParam Long customerId){
        return customerService.queryMessage( customerId);
    }
    /**
     * 更新用户信息
     * @param customerUpdateDTO
     */
    @PutMapping("updateMessage")
    public void updateMessage(@RequestBody CustomerUpdateDTO customerUpdateDTO){
        customerService.updateMessage(customerUpdateDTO);
    }
    /**
     * 更新用户头像
     * @param avatar
     * @param customerId
     */
    @PutMapping("/updateAvatar")
    public void updateAvatar(@RequestParam MultipartFile avatar, @RequestParam Long customerId){
        String avatarUrl = qiniuKodoUtil.upload(avatar);
        customerService.updateAvatar(customerId, avatarUrl);
    }
    /**
     * 查询用户地址
     * @param customerId
     * @return
     */
    @GetMapping("/queryCustomerAddress")
    public String queryCustomerAddress(@RequestParam Long customerId){
        return customerService.queryCustomerAddress(customerId);
    }
}